// mircoApp/new-auction/new_auction_Warehouse/new_auction_Warehouse.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: "1",
    show: false,
    selectItem: null,
    list: [],
    isLoadMore: true,
    page: 1,
    total_page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  tabChange(e) {
    let {
      name
    } = e.detail;
    this.setData({
      active: name
    })
    this.init();
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.init();
    this.getData();
  },
  closePopup() {
    this.setData({
      show: false,
      isPick: false,
      isPick_new: false,
      selectItem: null
    })
  },
  pickUpChild(e) {
    console.log(e)
    let {
      item
    } = e.detail;
    this.setData({
      show: true,
      selectItem: item,
      isPick: true
    })
  },
  tapActive(e) {
    let {
      item
    } = e.currentTarget.dataset;
    if (this.data.active == 2) return;
    wx.navigateTo({
      url: '/mircoApp/new-auction/new_auction_detail/new_auction_detail?id=' + item.activity_id,
    })
  },
  pickUp_newChild(e) {
    let {
      item
    } = e.detail;
    this.setData({
      show: true,
      isPick_new: true,
      selectItem: item,
    })
  },
  pickUp_new_popup(e) {
    let json = {
      new_auction_activity_id: e.detail.id,
      new_auction_pick_num: e.detail.value
    };
    console.log(json, 'wwww')
    wx.navigateTo({
      url: `/packageD/buy/myOrder_v2/myOrder_v2?tag=new_auction_mentioned&new_auction_activity_id=${json.new_auction_activity_id}&new_auction_pick_num=${json.new_auction_pick_num}`,
    })
    this.closePopup();
    this.init();
    this.getData();
  },
  pickUpChild_popup(e) {
    let json = {
      new_auction_id: e.detail.id,
      new_auction_pick_num: e.detail.value
    };
    wx.navigateTo({
      url: `/packageD/buy/myOrder_v2/myOrder_v2?tag=new_auction&new_auction_id=${json.new_auction_id}&new_auction_pick_num=${json.new_auction_pick_num}`,
    })
    this.closePopup();
    this.init();
    this.getData();
  },
  init() {
    this.setData({
      list: [],
      page: 1,
      total_page: 0,
      isLoadMore: true
    })
  },
  async getData() {
    let urlstr = "";
    let json = {};
    if (this.data.active == "1") {
      urlstr = "plugin.new-auction.frontend.activity.activityGoodsList";
    } else if (this.data.active == "2") {
      urlstr = "plugin.new-auction.frontend.order.extraList";
    } else if (this.data.active == "3") {
      urlstr = "plugin.new-auction.frontend.auction";
      json.is_usable = 1;
    }
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss(urlstr),
      data: json
    })
    if (data.result) {
      this.setData({
        list: data.data.data,
        total_page: data.data.last_page,
        isLoadMore: true
      })
    } else {
      app.tips(data.msg)
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})